package com.uhylab.uhuvinetest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.uhylab.uhuvinetest.R;
import com.uhylab.uhuvinetest.bean.Bean;

import java.util.List;

/**
 * Created by leige07 on 2016/3/24 0024.
 */
public class HistoryAdapter extends BaseAdapter {

    private List<Bean> list;
    private Context context;

    public HistoryAdapter(Context context, List<Bean> list) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder ;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_history,null);
            holder.date = (TextView) convertView.findViewById(R.id.item_time);
            holder.point1 = (ImageView) convertView.findViewById(R.id.item_point1);
            holder.point2 = (ImageView) convertView.findViewById(R.id.item_point2);
            holder.point3 = (ImageView) convertView.findViewById(R.id.item_point3);
            holder.point4 = (ImageView) convertView.findViewById(R.id.item_point4);
            holder.point5 = (ImageView) convertView.findViewById(R.id.item_point5);
            holder.point6 = (ImageView) convertView.findViewById(R.id.item_point6);
            holder.point7 = (ImageView) convertView.findViewById(R.id.item_point7);
            holder.point8 = (ImageView) convertView.findViewById(R.id.item_point8);
            holder.point9 = (ImageView) convertView.findViewById(R.id.item_point9);
            holder.point10 = (ImageView) convertView.findViewById(R.id.item_point10);
            holder.point0 = (ImageView) convertView.findViewById(R.id.item_point0);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Bean bean = list.get(position);

        holder.date.setText(bean.getDate());

        if (bean.getPoint1() == 2)  { holder.point1.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint1() == 3) { holder.point1.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint1() == 2)  { holder.point1.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint1() == 3) { holder.point1.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint2() == 2)  { holder.point2.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint2() == 3) { holder.point2.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint3() == 2)  { holder.point3.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint3() == 3) { holder.point3.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint4() == 2)  { holder.point4.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint4() == 3) { holder.point4.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint5() == 2)  { holder.point5.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint5() == 3) { holder.point5.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint6() == 2)  { holder.point6.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint6() == 3) { holder.point6.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint7() == 2)  { holder.point7.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint7() == 3) { holder.point7.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint8() == 2)  { holder.point8.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint8() == 3) { holder.point8.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint9() == 2)  { holder.point9.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint9() == 3) { holder.point9.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint10() == 2)  { holder.point10.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint10() == 3) { holder.point10.setImageResource(R.drawable.history_dangerous); }

        if (bean.getPoint0() == 2)  { holder.point0.setImageResource(R.drawable.history_bad); }
        else if (bean.getPoint0() == 3) { holder.point0.setImageResource(R.drawable.history_dangerous); }



        return convertView;
    }

    class ViewHolder {
        TextView date;
        ImageView point1;
        ImageView point2;
        ImageView point3;
        ImageView point4;
        ImageView point5;
        ImageView point6;
        ImageView point7;
        ImageView point8;
        ImageView point9;
        ImageView point10;
        ImageView point0;
    }

}
